473,480 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP dynamic dropdown-change form action based on user selection

4 New Member
Hello,

I have a dropdown which populates from a database.
When user selects option 1 from the dropdown, he should be directed to sample.php, if he selects option 2, then to sampleb.php and so on.

The code is as follows:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript">
  4.  
  5. function go(formname,url){
  6.  
  7.       document.getElementById(myteam).action = url;
  8.  
  9.       document.getElementById(myteam).submit();
  10.  
  11. }
  12.  
  13. </script>
  14. </head>
  15. <title>Homepage</title>
  16. <?php
  17. //dbconnect is a file which has the connection paramaters
  18. //to the server and the database.
  19. require ("dbconnect.php");
  20.  
  21.  
  22. $sqlquery="SELECT teamqueuename FROM teamqueue;";
  23. $results= mssql_query($sqlquery);
  24. ?>
  25. <body>
  26. <table> 
  27. <tr><td><center>Welcome to the homepage!</center><td></tr>
  28. <tr><td><br></td></tr>
  29. <tr><td>Please select a team queue</td></tr>
  30. <form name="myteam" method="get" target="_blank">
  31.  
  32. <tr><td><select name="myteam1" onChange="call()"> 
  33.  
  34. <?php
  35. while ($row=mssql_fetch_array($results)){
  36.  
  37.         $teamqueuename=$row["teamqueuename"];
  38.  
  39. echo "<option>$teamqueuename</option>";
  40.  
  41.  
  42.  
  43. }
  44. mssql_close($sqlconnect);
  45. ?>
  46. </select></td></tr>
  47. <tr><td><input type="submit" value="submit"></td></tr>
  48.  
  49. </form>
  50. <?php
  51. function call(){
  52. $myteam=$_get['myteam'];
  53. if ($myteam=="Build Team")
  54. {
  55.     go(myteam, "http://sample.php");
  56. }    
  57. if ($myteam=="PPG Team")
  58. {    
  59.     go(myteam, "http://sampleb.php");
  60.  
  61. }
  62. }
  63.     ?>    
  64. </table>
  65. </body>
  66. </html>
[Please use CODE tags when posting source code. Thanks! --pbmods]

Thank you..
Jun 29 '07 #1
3 7006
kovik
1,044 Recognized Expert Top Contributor
Firstly, you can't call a JavaScript function using PHP. Secondly, you don't really need JavaScript for this at all.

Post to the same page and, before anything is displayed, check the posted variable. If it meets the condition for the first page, use header() redirection to send them to the first page, or the second, or third, etc...
Jun 29 '07 #2
phpnewbie2007
4 New Member
Thanks for your reply.
I tried the header redirect..but it doesnt work.
Where am i going wrong??

Code:
<?php

$myteam1=$_post['myteam1'];
if ($myteam1=="Build Team")
{
header("location: newdata.html");
}
if ($myteam1=="PPG Team")

{
header("location: test/newdata.php");
}
?>
<html>
<head>
</head>
<title>Homepage</title>

<?php
//dbconnect is a file which has the connection paramaters
//to the server and the database.

require ("dbconnect.php");

$sqlquery="SELECT teamqueuename FROM teamqueue;";

$results= mssql_query($sqlquery);
$myteam1=$_get['myteam1'];
?>
<body>
<table>
<tr><td><center>Welcome to the homepage!</center><td></tr>
<tr><td><br></td></tr>
<tr><td>Please select a team queue</td></tr>
<form name= "myteam" method="post" target="_blank" action="test1.php">
<tr><td><select name="myteam1">
<?php
while ($row=mssql_fetch_array($results)){
$teamqueuename=$row["teamqueuename"];
echo "<option>$teamqueuename</option>";

}
mssql_close($sqlconnect);
?>
</selec></td></tr>

<tr><td><input type="submit" value="submit"></td></tr>

</form>

</table>
</body>
</html>
Jun 29 '07 #3
kovik
1,044 Recognized Expert Top Contributor
A lot of things. :-p

Firstly, never assume that a variable has been posted. Secondly, the header() function takes absolute paths. I believe it is either a browser issue or a server issue, but not everything recognizes relative paths correctly.

But I can't really help you until you tell me what error messages you are getting.
Jun 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
3728
by: adam | last post by:
Hi - im looking to have two drop down boxs one with makes of car and the second drop down box to automatically populate with all the model of that particular make of car. there are about 50 makes...
6
2211
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car...
8
1676
by: Drew | last post by:
I am trying to build a small app that shows a Course Title from the database, then displays a dropdown full of categories for the user to choose one... I thought a loop would be the best way to...
4
1027
by: Niks | last post by:
Hi, I have to create a DataGrid which has 5 columns (only for display not for Edit). Problem is with one column, which displays the database value if present else it has to display DropDownlist in...
0
1394
by: Just Me | last post by:
My Dynamic dropdown menus are appearing above the text below. How can I prevent this, I have tried setting the zorder high for them, but it makes not difference. Cheers
1
3111
by: Steve Richter | last post by:
I am using <div align=centerto center a horizontal menu on the page. Problem is the center align of the div is rippling down to the menu items and causing the text of the dynamic popup sub menu...
0
1757
by: Javilen | last post by:
Hello, Maybe one of you can offer a possible solution to the problem I have below. The request to me is to build a dynamically populating dropdown list from a text box.(something similar to...
2
1480
by: chowdary | last post by:
hi, Iam new to javascript. I'm wondering how to go about creating two dropdown boxes such that when you select a value from the first one, the second is populated with values that depend on the...
3
2042
by: d1156676 | last post by:
Hi I have a Dynamic dropdown reading in data from a MySql database, I need to refresh the dropdown when the database is updated without refreshing the whole page. I have had a go at trying to...
1
2645
by: sydd | last post by:
Hi, I was wondering if it's possible to create a dynamic dropdown menu from this code. if($rs->getNumRows() > 0){ $intProjectCount = 1; $htmlOut ="<table width='100%' border='0'...
0
7065
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6924
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7124
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6778
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7057
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4808
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1325
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
576
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.